toNonZeroIntOrNull
Returns this number as a NonZeroInt, which may involve rounding or truncation, or returns null
if this number equals zero.
var result: NonZeroInt? = 1.toNonZeroIntOrNull()
println(result) // 1
result = 0.toNonZeroIntOrNull()
println(null) // 0
Content copied to clipboard
You can use the toNonZeroIntOrThrow function for throwing an IllegalArgumentException instead of returning null
when this number equals zero.